package com.infinity.springboot.thymeleaf.vo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.http.HttpStatus;

/**
 * @Author: wuxiang
 * @Description:
 * @Date: Create in 2020/6/16 20:52
 */
@Getter
@Setter
public class ResultBean<T> {


    private String msg;

    private int code;

    private long date;

    private T data;


    private ResultBean(T data) {

        this(HttpStatus.OK.getReasonPhrase(), HttpStatus.OK.value(), data);
    }

    private ResultBean() {
    }
    private ResultBean(String msg, int code, T data) {
        super();
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    private ResultBean(T data, String msg) {
        super();
        this.msg = msg;
        this.data = data;
    }

    public static ResultBean ok(){
        return new ResultBean(null);
    }


    public static ResultBean ok(Object data){
        return new ResultBean(data);
    }

    public static ResultBean ok(Object data,String msg){
        return new ResultBean(data,msg);
    }

    public static ResultBean error(Object data,String msg,int code){
        return new ResultBean(msg, code, data);
    }

    public static ResultBean error(String msg){
        return new ResultBean(msg, HttpStatus.BAD_REQUEST.value(), null);
    }
}
